package Q2;

import java.util.Scanner;

public class Main {

    public static int n;
    public static int[][] arr; //arr[i][0]
    public static int ret;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        n = scanner.nextInt();
        arr = new int[n][2];
        for (int i = 0; i < n; i++) {
            arr[i][0] = scanner.nextInt();
            arr[i][1] = scanner.nextInt();
        }

        dfs(0, new boolean[n]);
        System.out.println(ret);
    }

    public static void dfs(int index, boolean[] flag) {
        if (index == n) {
            int end = 0; //前一场活动的结束时间
            int count = 0; //选择的活动个数
            for (int i = 0; i < n; i++) {
                if (flag[i]) {
                    if (arr[i][0] < end) {
                        return;
                    }
                    end = arr[i][1];
                    count++;
                }
            }
            ret = Math.max(ret, count);
            return;
        }

        for (int i = index; i < n; i++) {
            //选
            flag[i] = true;
            dfs(i + 1, flag);
            //回溯
            flag[i] = false;

            //不选
            dfs(i + 1, flag);
        }
    }
}
